草庐IT

php - Laravel hasMany 和 belongsTo 参数

全部标签

c# - BeginXXX 中 FromAsync 的参数太多?

我有一个具有以下签名的异步方法:IAsyncResultBeginGetMyNumber(stringfoo,stringbar,stringbat,intbam,AsyncCallbackcallback,objectstate)我想像这样使用Factory.FromAsync来执行它:varresult=Task.Factory.FromAsync(instance.BeginGetMyNumber,instance.EndGetMyNumber,"foo","bar","bat",100,/*bam*/null);但我收到以下错误:Argument1:cannotconvertf

c# - 带有参数的 Dispatch.Invoke( new Action...)

以前我有Dispatcher.Invoke(newAction(()=>colorManager.Update()));从另一个线程更新显示到WPF。由于设计原因,我不得不更改程序,并且我必须将ColorImageFrame参数传递到我的ColorStreamManager.Update()方法中。正在关注this链接,我将调度程序修改为:Dispatcher.Invoke(newAction((p,v)=>p.Update(v)));它编译正常,但根本无法运行。VS2010说“参数计数不匹配。”在我的ColorStreamManager.Update()方法中我有RaisePrope

c# - 如何为具有类型参数约束的泛型类型编写扩展方法?

我正在使用一个任务特定的.NET平台,它是预编译的,而不是开源的。对于某些任务,我需要扩展此类,而不是继承它。我只是想添加一个方法。首先我想向您展示一个dummycode现有类:publicclassMatrixwhereT:new(){...publicTvalues[,];...}我想通过以下方式扩展这个类:publicstaticclassMatrixExtension{publicstaticTgetCalcResult(thisMatrixmat){Tresult=0;...returnresult;}}我从许多谷歌链接中得到了这个语法,所以不知道它是否正确。编译器告诉我没有

c# - 强制派生类使用参数实现基类构造函数

是否可以对需要实现构造函数(带参数)的派生类强制执行编译时契约?我有一个基类,它的构造函数需要一个参数:publicclassFooBase{protectedintvalue;publicFooBase(intvalue){this.value=value;}publicvirtualvoidDoSomething(){thrownewNotImplementedException();}}我想强制派生我的基类来实现相同的构造函数:publicclassFoo:FooBase{publicFoo(intvalue):base(value){}publicoverridevoidDoS

c# - 模拟使用参数的函数

我有一个使用out参数的函数。我如何模拟此功能?我的职能是:GetProperties(outstringname,outstringpath,outstringextension);在我的原始代码中,我是这样做的:stringName;stringPath;stringExtension;MyObject.GetProperties(outName,outPath,outExtension);现在,我该如何模拟它? 最佳答案 你应该在调用方法之前分配变量的值:stringName="name";stringPath="path";

c# - 如何将字符串参数传递给 t4 模板

您好,我正在尝试找到一种将普通字符串作为参数传递给文本模板的方法。这是我的模板代码,如果有人能告诉我我需要用C#编写什么来传递我的参数并创建类文件。这将非常有帮助,谢谢。namespace{usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Xml;//////Thisclassdescribesthedatalayerrelatedto./////////>OriginalVersion///publicpartialclass:DataObject{#regionconstructor//

C# 参数引用和 .net 垃圾回收

我一直在努力弄清楚.NET垃圾收集系统的复杂性,并且我有一个与C#引用参数相关的问题。如果我理解正确的话,方法中定义的变量存储在堆栈中,不受垃圾回收的影响。所以,在这个例子中:publicclassTest{publicTest(){}publicintDoIt(){intt=7;Increment(reft);returnt;}privateintIncrement(refintp){p++;}}DoIt()的返回值将为8。由于t的位置在堆栈上,因此该内存不能被垃圾回收或压缩,并且Increment()中的引用变量将始终指向t的正确内容.但是,假设我们有:publicclassTes

c# - 使用数组作为 string.Format() 的参数

当尝试使用数组作为string.Format()方法的参数时,出现以下错误:FormatException:Index(zerobased)mustbegreaterthanorequaltozeroandlessthanthesizeoftheargumentlist.代码如下:place=newint[]{1,2,3,4};infoText.text=string.Format("Player1:{0}\nPlayer2:{1}\nPlayer3:{2}\nPlayer4:{3}",place);数组包含四个值,String.Format()中的参数也相同。是什么导致了这个错误?(

c# - “System.DateTime”不是有效的 Windows 运行时参数类型

我使用的是C#类,它在我的Windows应用商店应用程序(C#)中运行良好。但是当我尝试在Windows运行时组件中使用它时,出现以下错误:Calculator.Calculate(System.DateTime)'hasparameter'dateTime'oftype'System.DateTime'.'System.DateTime'isnotavalidWindowsRuntimeparametertype.类中的示例对象:publicDateTimeCalculate(DateTimedateTime){intdayNumberOfDateTime=ExtractDayNum

c# - 匿名委托(delegate)作为函数参数

我正在尝试将匿名委托(delegate)(无输入参数,无返回值)的参数传递给函数。像这样:privatefunctionDoSomething(delegatecmd){cmd();}然后,我想用这个函数来调用函数:DoSomething(delegate{Console.WriteLine("Hooah!");});我想要这种特定的方式,因为它易于使用的写作风格。可能吗? 最佳答案 正是出于此类目的,Microsoft创建了Action和Func.NET框架中的包装器类。这两个类都依赖于anonymousfunctions.如果不